//46
function permute(nums) {
  const result = [];
  function travel(arr, nums) {
    if (nums.length === 0) {
      result.push(arr);
      return;
    }
    for (let i = 0; i < nums.length; i++) {
      travel([...arr, nums[i]], nums.toSpliced(i, 1));
    }
  }
  travel([], nums);
  return result;
}
permute([1, 2, 3]);
